<template>
	<view class="container">
		<view class="layout">
			<view class="list">
				<view class="list-box" v-if="state.status == 0">
					<view class="top">
						<view class="title">补货数量</view>
						<input class="input" type="number" v-model="num" placeholder="请填写补货数量" />
						<view class="btn" @click="submit">提交补货</view>
					</view>
				</view>
				<view class="list-box bjt" v-else>
					<view class="body">
						<view class="tipMsg" v-if="state.status == 1">申请补货已提交，请耐心等待平台审核</view>
						<view class="tipMsg" v-else-if="state.status == 2">申请补货审核通过，请及时关注物流动态</view>
						<view class="tipMsg" v-else-if="state.status == 3">申请补货审核已拒绝</view>
						<view class="msg">
							<view class="label">补货数量</view>
							<view class="text">{{ state.num }}</view>
						</view>
						<view class="msg">
							<view class="label">下单时间</view>
							<view class="text">{{ state.time }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="footer" v-if="state.status == 2">
			<view class="btn-group-right">
				<view class="btn" @click="chakanwuliu">查看物流</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { post } from '@/request/index.js';
import { dayjs } from '@/static/dayjs.min.js';

let num = ref('');
let state = reactive({
	num: 0,
	status: 0,
	time: '',
	expressno: ''
});

onLoad((option) => {
	state.status = option.status;
	if (option?.num) {
		state.num = option.num;
		state.time = option.time;
		state.expressno = option.expressno;
	}
});
// 提交补货
const submit = async () => {
	const res = await post('agent/change/bu', { num: num.value });
	if (res.code == 200) {
		state.status = 1;
		state.num = num.value;
		state.time = dayjs().format('YYYY-MM-DD HH:mm:ss');
	}
};
//查看物流
const chakanwuliu = async () => {
	uni.navigateTo({
		url: `/pages/wuliudetail/wuliudetail?expressno=${state.expressno}`
	});
};
</script>

<style scoped lang="scss">
.layout {
	.body {
		background-color: transparent;
	}
}
</style>
